package com.yachang.qym.usbhost.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yachang.qym.usbhost.R;
import com.yachang.qym.usbhost.model.ContactModel;

import java.util.List;

/**
 * Created by qym on 2015/12/21.
 */
public class ContactAdapter extends BaseAdapter{

    private Context mContext;
    private List<ContactModel> mModels;
    public ContactAdapter(Context context, List<ContactModel> models){
        mContext = context;
        mModels = models;
    }

    @Override
    public int getCount() {
        return mModels.size();
    }

    @Override
    public Object getItem(int position) {
        return mModels.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_contact, null);
            holder = new ViewHolder();
            holder.name = (TextView) convertView.findViewById(R.id.tv_contact_name);
            holder.style = (TextView) convertView.findViewById(R.id.tv_contact_style);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.name.setText(mModels.get(position).getName());
        switch(mModels.get(position).getStyle()){
            case 0:holder.style.setText("组呼");break;
            case 1:holder.style.setText("个呼");break;
            case 2:holder.style.setText("全呼");break;
            default:holder.style.setText("呼叫类型错误！");break;
        }
        return convertView;
    }

    public class ViewHolder{
        public TextView name;
        public TextView style;
    }
}
